package com.rpj.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.rpj.entity.UserEntity;

public class LoginInterceptor implements HandlerInterceptor{
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
	}
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
	}
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		//获取session
		HttpSession session = request.getSession();
		//获取session在controller层存储的属性
		UserEntity stu = (UserEntity)session.getAttribute("student");
		if(stu==null) {
			response.sendRedirect("/login.html");
			return false;
		}else {
			return true;
		}
		
	}
}
